home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 446_01 / DOC / SPLINES / EX / PROG8.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-18  |  717 b   |  24 lines

  1. // ******************* File: prog8.C *****************
  2. // Demonstration of least squares spline approximation
  3. #include <BSpline.h>
  4. int main()
  5. {
  6.   // The data are 10 discrete points:
  7.   VecSimple(real) x(10),f(10);
  8.   x.scan("1.1 1.5 1.8 2.1 2.2 2.4 3.4 3.6 4.2 4.8");
  9.   for (int i=1; i<=10; i++) f(i)=4*x(i)*x(i)*x(i)+3*x(i);
  10.  
  11.   KnotVec knots(5);
  12.   knots.scan("1 2 3 4 5");      // alternative to knots.fill(1,5)
  13.   knots.regulate(4);
  14.   knots.print(s_o,"knot vector");
  15.   x.print(s_o,"x data");  f.print(s_o,"f data");
  16.  
  17.   SplineSpace space(knots,4);   // cubic spline
  18.   BSpline spline;
  19.   spline.redim(space);
  20.   spline.leastSquareInterpolation(x,f);
  21.   s_o <<"cubic spline at x=2.0 : " << spline(2.0) <<'\n';
  22.   return 0;
  23. }
  24.